package com.xzc.java8.A_lambda.lambda5;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;

public class MethodRefNew {
    public static <T, R> List<R> map(List<T> list, Function<T, R> f) {
        List<R> result = new ArrayList<>();
        for (T s : list) {
            result.add(f.apply(s));
        }
        return result;
    }

    public static void main(String[] args) {
        Supplier<Apple> c1 = () -> new Apple();
        Apple a1 = c1.get();
        Supplier<Apple> c2 = Apple::new;
        Apple a2 = c2.get();

        Function<Integer, Apple> c3 = (weight) -> new Apple(weight);
        Apple a3 = c3.apply(10);
        Function<Integer, Apple> c4 = Apple::new;
        Apple a4 = c4.apply(20);

        List<Integer> weights = Arrays.asList(7, 3, 4, 10);
        List<Apple> apples0 = map(weights, (weight) -> new Apple(weight));
        List<Apple> apples = map(weights, Apple::new);

        BiFunction<String, Integer, Apple> c5 = (color, weight) -> new Apple(color, weight);
        BiFunction<String, Integer, Apple> c6 = Apple::new;
    }
}
